package com.example.keli.ui.worldwall;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.DataUtil;
import com.example.keli.base.utils.GlideUtil;
import com.example.keli.ui.center.ActivieList;

import java.util.List;

import cn.bingoogolapple.photopicker.activity.BGAPhotoPreviewActivity;
import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;

/**
 * description $desc$
 * created by jerry on 2019/3/18.
 */
public class CircleAdapter extends BaseQuickAdapter<CircleBean, BaseViewHolder> implements BGANinePhotoLayout.Delegate{

    private Context mContext;
    private int mType;

    public CircleAdapter(List<CircleBean> mData, Context context, int type) {
        super(R.layout.item_circle, mData);
        this.mContext = context;
        this.mType = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, CircleBean dataBean) {
        BGANinePhotoLayout ninePhotoLayout = helper.getView(R.id.circle_photos);
        ninePhotoLayout.setDelegate(this);
        ninePhotoLayout.setData(dataBean.getPhotos());

        ImageView avater = helper.getView(R.id.iv_circle_avatar);
        GlideUtil.displayCircle(mContext, avater, dataBean.getAvater());
        helper.setText(R.id.tv_circle_username, dataBean.getName());
        helper.setText(R.id.tv_circle_content, dataBean.getContent());
        helper.setText(R.id.tv_circle_city, dataBean.getCity());
        helper.setText(R.id.tv_circle_date, dataBean.getDate());
        helper.setText(R.id.tv_circle_praise, dataBean.getPraises());
        helper.setText(R.id.tv_circle_comment, dataBean.getComments());

    }

    @Override
    public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
        BGAPhotoPreviewActivity.IntentBuilder photoPreviewIntentBuilder = new BGAPhotoPreviewActivity.IntentBuilder(mContext)
                .saveImgDir(null); // 保存图片的目录，如果传 null，则没有保存图片功能
        if (ninePhotoLayout.getItemCount() == 1) {
            // 预览单张图片
            photoPreviewIntentBuilder.previewPhoto(ninePhotoLayout.getCurrentClickItem());
        } else if (ninePhotoLayout.getItemCount() > 1) {
            // 预览多张图片
            photoPreviewIntentBuilder.previewPhotos(ninePhotoLayout.getData())
                    .currentPosition(ninePhotoLayout.getCurrentClickItemPosition()); // 当前预览图片的索引
        }
        mContext.startActivity(photoPreviewIntentBuilder.build());
    }
}
